#!/usr/bin/python

from sys import exit, argv, stderr
from os import system

if(len(argv) < 2):
    print """usage: %s file
    """ % argv[0]
    exit(-1)
    
file=open("./node","r")

r = {}

for lr in file:
    if(lr[0] == "#"):
        continue
    l = lr.split()
    if(len(l) == 0):
        continue
    if(len(l) < 4):
        raise Exception("Malformed nodes file! " + lr)
    r["prefixip"] = l[0]
    r["bssid"] = l[1]
    r["router"] = l[2]
    r["power"] = l[3]
try: file.close()
except: pass

#out[r["prefixip"]] = r

system("""killall click &> /dev/null""")


system("""
python config.py %(prefixip)s %(bssid)s %(router)s %(power)s > config.click 2> config.log
""" % r)

system("""click-align -u -f config.click -o config-align.click""")

system("""click config-align.click &> click.log &""")
